package com.weimengchao.redisson.conftoller;

import com.weimengchao.redisson.test.MyProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:配置管理接口
 * @author: 魏孟超
 * @createDate: 2021-11-23 0:07
 */
@Slf4j
@RestController
@RequestMapping
//public class RefreshController implements ApplicationListener<ApplicationStartedEvent> {
public class RefreshController {

    @Autowired
    ContextRefresher contextRefresher;

    @Autowired
    MyProperties myProperties;

    @Value("${remote.test}")
    private String test;

    /**
     * 刷新配置接口
     * 限制一分钟只能请求一次
     */
    @GetMapping("refresh")
    public String refresh() {
        contextRefresher.refresh();
        return test;
    }

    @GetMapping("myProperties")
    public String myProperties() {
        String name = myProperties.getName();
        return name;
    }
}
